/*
 *  Copyright 2012 Dirk Vranckaert
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package eu.vranckaert.vvl.service.impl;

import android.content.Context;
import android.graphics.Bitmap;
import android.util.Log;
import eu.vranckaert.vvl.exception.webservice.WebServiceException;
import eu.vranckaert.vvl.exception.ServiceException;
import eu.vranckaert.vvl.exception.webservice.WebServiceRequestFailureException;
import eu.vranckaert.vvl.model.TrafficInfoGraphicalEnum;
import eu.vranckaert.vvl.service.InformationGraphicalService;
import eu.vranckaert.vvl.utils.context.Preference;

/**
 * User: DIRK VRANCKAERT
 * Date: 21/02/12
 * Time: 11:56
 */
public class InformationGraphicalServiceImpl extends WebServiceImpl implements InformationGraphicalService {
    private static final String LOG_TAG = InformationGraphicalServiceImpl.class.getSimpleName();

    public InformationGraphicalServiceImpl(Context ctx) {
        super(ctx);
    }

    @Override
    public Bitmap getTrafficImage(TrafficInfoGraphicalEnum.Region region) throws WebServiceException, WebServiceRequestFailureException {
        String imgUrl = String.format(TrafficInfoGraphicalEnum.GRAPHICAL_IMAGE_URL,
                Preference.getTrafficInfoGraphicalImageSize(ctx), region.getValue(), false);

        try {
            return doImageGet(imgUrl);
        } catch (WebServiceException e) {
            Log.e(LOG_TAG, e.getMessage());
            throw e;
        }
    }
}
